package cn.com.surker.base.pump.service.impl;

import cn.com.surker.base.pump.dao.PumpNormDao;
import cn.com.surker.base.pump.entity.PumpNorm;
import cn.com.surker.base.pump.service.PumpNormService;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 泵送规格 基础实现
 * </p>
 *
 * @author admin
 * @since 2024-07-09
 */
public abstract class PumpNormBaseImpl extends ServiceImpl<PumpNormDao, PumpNorm> implements PumpNormService {

	@Resource
	protected PumpNormDao pumpNormDao;

	@Cacheable(cacheNames = "pumpNormCache")
	public List<PumpNorm> findAll() {
		QueryWrapper<PumpNorm> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("status", 0);
		List<PumpNorm> pumpNormList = pumpNormDao.selectList(queryWrapper);
		if (pumpNormList == null || pumpNormList.size() == 0)
			return null;
		return pumpNormList;
	}

	@Override
	public PumpNorm findByErpId(Long originId, Long erpId) {
		return pumpNormDao.findByErpId(originId, erpId);
	}

	@Override
	@Cacheable(cacheNames = "pumpNormCache", key = "#name == null ? 'NULL' : #name")
	public List<PumpNorm> findList(String name) {
		QueryWrapper<PumpNorm> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("status", 0);
		if (StringUtils.isNotBlank(name)) {
			queryWrapper.like("name", name);
		}
		List<PumpNorm> pumpNormList = pumpNormDao.selectList(queryWrapper);
		return pumpNormList;
	}

	@Override
	public List<PumpNorm> findBySaleCon(Long conId) {
		if (conId == null) {
			return null;
		}
		return pumpNormDao.findBySaleCon(conId);
	}
}